#include <iostream>
#include <pthread.h>
#include <unistd.h>

using namespace std;

int g_val = 0;

void *threadRun1(void *args){
    const char *name = static_cast<const char *>(args);
    while(true){
        sleep(1);
        cout << name << " " << getpid() << "&g_val:" << &g_val << " g_val:" << g_val << endl;
    }
}

void *threadRun2(void *args){
    const char *name = static_cast<const char *>(args);
    while(true){
        sleep(1);
        cout << name << " " << getpid() << "&g_val:" << &g_val << " g_val:" << g_val++ << endl;
    }
}

int main(){
    pthread_t t1, t2;

    pthread_create(&t1, nullptr, threadRun1, (void*)"thread1");
    pthread_create(&t2, nullptr, threadRun2, (void*)"thread2");

    while(true){
        sleep(1);
        cout << "main thread " << getpid() << "&g_val:" << &g_val << " g_val:" << g_val << endl;
    }
}